<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/23
 * Time: 14:55
 */

//我这个类是给 C 控制器访问的，不是Application.class.php 访问的

namespace Shop;
//判断权限，防止用户直接访问
if(!defined("SHOP")){
    header("Location:../index.php");
}

class View{
    //1.加载模板
    //$file 默认值 为方法同名的HTML 文件
    public function display($file=SHOP_F){
        //加载模板
        $path=SHOP_VIEW.str_replace('Controller','',SHOP_C).'/'.$file.'.html';

        if(is_file($path)){
            //定义变量，HTML可以直接访问
           foreach($this->data as $k=>$v){
//              $$k  可变变量 声明一个 变量变量名为$k的值 ,变量值为$v
               $$k=$v;
           }
            include $path;
        }else{
            exit('模板不存在！');
        }
    }

    //2.传递参数
    public $data=array(); //公共属性用来传递参数

    //定义方法用来修改公共属性
    public function assign($name,$value){
        $this->data[$name]=$value;
    }

    /****后台加载HTML公共模块*****/
    public function _Ameta(){
        include SHOP_VIEW.'Public/_meta.html';
    }
    public function _Amenu(){
        include SHOP_VIEW.'Public/_menu.html';
    }
    public function _Afooter(){
        include SHOP_VIEW.'Public/_footer.html';
    }
    public function _Aheader(){
        include SHOP_VIEW.'Public/_header.html';
    }

    /*****前台加载HTML 公共模块*******/
    public function _Hhead(){
        include SHOP_VIEW.'Public/_head.html';
    }
    public function _Hfooter(){
        include SHOP_VIEW.'Public/_footer.html';
    }
    public function _Hleft(){
        include SHOP_VIEW.'Public/_left.html';
    }
}